package edu.fpa.day0806;

public class SynTest01 implements Runnable{
    private int ticket = 10;
    public  void run() {
        test();
    }

    public static void main(String[] args) {
        SynTest01 w = new SynTest01();
        new Thread(w,"码农").start();
        new Thread(w,"码畜").start();
    }
    public synchronized void test(){
        while(true) {
            if(ticket<0)
                break;
            else {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"-->"+ticket);
                ticket--;
            }
        }
    }
}